package com.travel.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.travel.base.BaseDao;
import com.travel.base.impl.BaseServiceImpl;
import com.travel.bean.Hotspot;
import com.travel.bean.SpotPicture;
import com.travel.bean.Strategy;
import com.travel.bean.StrategyPage;
import com.travel.dao.StrategyDao;
import com.travel.service.StrategyService;
import com.travel.service.UserService;
import com.travel.utils.PageHelper;

@Service("strategyServiceImpl")
public class StrategyServiceImpl extends BaseServiceImpl<Strategy> implements StrategyService {

	@Resource(name="strategyDaoImpl")
	private StrategyDao strategyDaoImpl;
	@Resource(name="userServiceImpl")
	private UserService userService;
	
	@Override
	public BaseDao<Strategy> getBaseDao() {
		// TODO Auto-generated method stub
		return strategyDaoImpl;
	}
	/**
	 * 在首页展示三个首页攻略
	 */
	@Override
	public List<Map> queryByPageIndex(Map map, Integer pageNum, Integer pageSize) {
		List<Strategy> strategys=strategyDaoImpl.queryByPage(map, pageNum, pageSize);
		List<Map> list=new ArrayList();
		for (Strategy strategy : strategys) {
			Map maps=new HashMap();
			list.add(maps);
		}
		// TODO Auto-generated method stub
		return list;
	}
	/**
	 * 在攻略列表中展示旅游攻略数据
	 */
	@Override
	public PageHelper queryByPageList(Map map, Integer pageNum, Integer pageSize) {
		// TODO Auto-generated method stub
		List<Strategy> strategys=strategyDaoImpl.queryByPage(map, pageNum, pageSize);
		List<Map> list=new ArrayList();
		for (Strategy strategy : strategys) {
			Set<StrategyPage> strategyPages=strategy.getStrategyPages();
			StrategyPage myfirstPage=null;
			for (StrategyPage strategyPage2 : strategyPages) {
				myfirstPage=strategyPage2;
				break;
			}
			Map maps=new HashMap();
			maps.put("id", strategy.getId());
			maps.put("title", strategy.getTitle());
			maps.put("p1", myfirstPage.getTitle());
			maps.put("page1", myfirstPage.getContent());
			maps.put("praise", strategy.getPraiseCount());
			maps.put("readcount", strategy.getReadCount());
			maps.put("time", strategy.getCreateTime());
			maps.put("author", userService.getEntryById(strategy.getCreateByUser()).getName());
			list.add(maps);
		}
		PageHelper page=new PageHelper();
		page.setList(list);
		page.setPageSize(pageSize);
		page.setCurrentPageNo(pageNum);
		page.setTotalCount(strategyDaoImpl.queryByPageCount(map));
		// TODO Auto-generated method stub
		return page;
	}
	/**
	 * 按照分页查询总记录数
	 */
	@Override
	public Integer queryByPageCount(Map map) {
		// TODO Auto-generated method stub
		return strategyDaoImpl.queryByPageCount(map);
	}
}
